﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Golf.WebUI.AdminShow.Admin
{
    public partial class Right : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind_OrderState();
                Bind_Order();
                New_User();
                Pro_all();
            }
        }
        /// <summary>
        /// 产品统计
        /// </summary>
        private void Pro_all()
        {
            Golf.BLL.Golf_Product bll = new Golf.BLL.Golf_Product();//产品
            DataSet ds = bll.GetAllList();
            List<Golf.Model.Golf_Product> list = bll.DataTableToList(ds.Tables[0]);//产品
            int sum_Count = 0;//总产品
            int Promotion_Count = 0;//是否促销  产品数量
            int Show_Count = 0;//是否显示
            int Commend_Count = 0;//是否推荐
            int Grounding_Count = 0;//上架商品
            foreach (var item in list)
            {
                if (item.IsPromotion)
                {
                    Promotion_Count += 1;
                }
                if (item.IsShow)
                {
                    Show_Count += 1;
                }
                if (item.isCommend)
                {
                    Commend_Count += 1;
                }
                if (item.IsGrounding)
                {
                    Grounding_Count += 1;
                }
                sum_Count += 1;
            }
            Sum_Count_lab.Text = sum_Count + "";
            Promotion_Count_lab.Text = Promotion_Count + "";
            Show_Count_lab.Text = Show_Count + "";
            Commend_Count_lab.Text = Commend_Count + "";
            Grounding_Count_lab.Text = Grounding_Count + "";
        }

        /// <summary>
        /// 订单状态
        /// </summary>
        public void Bind_OrderState()
        {
            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();//订单
            Golf.BLL.Golf_OrderStateCode oState = new Golf.BLL.Golf_OrderStateCode();//状态
            DataSet ds = bll.GetAllList();
            List<Golf.Model.Golf_Order> list = bll.DataTableToList(ds.Tables[0]);//订单
            List<Golf.Model.Golf_OrderStateCode> oList = oState.DataTableToList(oState.GetAllList().Tables[0]);// 状态 
            List<OrderState> list_ordre = new List<OrderState>();
            foreach (var item in list)
            {
                OrderState s = new OrderState();
                foreach (var ostate in oList)
                {
                    if (item.OrderStateCodeId == int.Parse(ostate.OrderStateName))
                    {
                        s.Str = ostate.OrderStateCodeRemarks;
                        s.Count += 1;
                    }
                }
                s.SumCount += 1;
                Label1.Text = s.SumCount + "";
                list_ordre.Add(s);
            }
            Repeater2.DataSource = list_ordre;
            Repeater2.DataBind();
        }
        /// <summary>
        /// 订单  绑定
        /// </summary>
        public void Bind_Order()
        {
            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();//订单
            Repeater1.DataSource = bll.GetAllList();
            Repeater1.DataBind();
        }

        /// <summary>
        /// 新  客户
        /// </summary>
        public void New_User()
        {
            Golf.BLL.Golf_User bll = new Golf.BLL.Golf_User();//订单
            Repeater3.DataSource = bll.GetList(10, "", "RegisterTime desc");
            Repeater3.DataBind();
        }

    }

    /// <summary>
    /// 订单状态
    /// </summary>
    public partial class OrderState
    {
        public OrderState()
        { }
        #region Model
        private int _sumCount;
        /// <summary>
        /// 订单总数
        /// </summary>
        public int SumCount
        {
            set { _sumCount = value; }
            get { return _sumCount; }
        }

        private string _str;
        /// <summary>
        /// 状态名称
        /// </summary>
        public string Str
        {
            get { return _str; }
            set { _str = value; }
        }
        private int _count;
        /// <summary>
        /// 状态数量
        /// </summary>
        public int Count
        {
            get { return _count; }
            set { _count = value; }
        }
        private string _remark;
        /// <summary>
        /// 状态说明
        /// </summary>
        public string Remark
        {
            get { return _remark; }
            set { _remark = value; }
        }
        #endregion Model
    }
}
